package com.yanqu.road.server.timer.cross.battle.timer.task;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangData;
import com.yanqu.road.pb.huashigang.HuaShiGangProto;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.cross.battle.HuaShiGangActivity;
import com.yanqu.road.server.manager.cross.battle.HuaShiGangMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.executor.GeneralTask;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

public class HuaShiGangGetAbilityTask extends GeneralTask {

	@Override
	public void doRun() {
		for (HuaShiGangActivity huaShiGangActivity : HuaShiGangMgr.getHuaShiGangActivityMap().values()) {
			ActivityInfo activityInfo = huaShiGangActivity.getActivityInfo();
			HuaShiGangData huaShiGangData = huaShiGangActivity.getHuaShiGangData();
			List<Long> serverList = StringUtils.stringToLongList(activityInfo.getServerListStr(), ",");
			for (long serverId : serverList) {
				if (!huaShiGangData.getAbilityMap().containsKey(serverId)) {
					HuaShiGangProto.HuaShiGangGetAbilityReqMsg.Builder builder = HuaShiGangProto.HuaShiGangGetAbilityReqMsg.newBuilder();
					builder.setActivityId(activityInfo.getActivityId());
					MessageHelper.sendPacket(serverId, -1, YanQuMessageUtils.buildMessage(GameProtocol.S_HUA_SHI_GANG_GET_ABILITY_FROM_CROSS, builder));
				}
			}
		}
		HuaShiGangMgr.checkExpired();
	}

}
